import re

import allure
from playwright.sync_api import Page

from pages.base_page import BasePage
from utils.test_data_utils import TestDataUtils


class InsurancePageDZD(BasePage):
    def __init__(self, page: Page):
        super().__init__(page, yaml_path="insurance_page_DZD.yaml")  # 指定YAML路径

    @property
    @allure.step("添加被保人")
    def add_insure_button(self):
        self.locator('add_insure_btn').click()

    @allure.step("填写三要素")
    def fill_insurance_form(self,data):
        self.locator("name_input").click()
        self.locator("name_input").fill(data["name"])
        self.locator("cert_no_input").fill(data["certNo"])
        self.locator("phone_input").fill(data["phone"])
        self.locator("sms_code_input").fill("1234")
        return data

    @allure.step("填写配偶三要素")
    def fill_consort_insurance_form(self,data):
        self.locator('consort_insurance_button').click()
        self.locator("consort_name_input").click()
        self.locator("consort_name_input").fill(data["name"])
        self.locator("consort_cert_no_input").fill(data["certNo"])
        # self.locator("confirm_button").click()
        return data

    @allure.step("填写子女三要素")
    def fill_child_insurance_form(self,data):
        # self.locator('add_insure_btn').click()
        self.locator('children_insurance_button').click()
        self.locator("children_name_input").click()
        self.locator("children_name_input").fill(data["name"])
        self.locator("children_cert_no_input").fill(data["certNo"])
        # self.locator("confirm_button").click()
        return data

    @allure.step("填写父母三要素")
    def fill_parents_insurance_form(self,data):
        # self.locator('add_insure_btn').click()
        self.locator('parents_insurance_button').click()
        self.locator("parents_name_input").click()
        self.locator("parents_name_input").fill(data["name"])
        self.locator("parents_cert_no_input").fill(data["certNo"])
        # self.locator("confirm_button").click()
        return data

    @allure.step("确认投保")
    def apply_policy (self):
        self.locator('apply_policy_button').click()
        self.locator("confirm_policy_button").click()

    @allure.step("确认变更保障计划")
    def change_plan (self):
        # self.locator('change_plan_button').click()
        self.locator("close_box").click()
        self.locator("new_jkgz_btn").click()